const path = require("path");
const Koa = require("koa");
const session = require("koa-session");
const bodyparser = require("koa-bodyparser");
const views = require("koa-views");
const static = require("koa-static");
const page = require("./routes/page");
const api = require("./routes/api");
const connect = require("./connect");

const app = new Koa();

// 静态服务
app.use(static(path.join(__dirname, "static")));
// 模板引擎
app.use(views(path.join(__dirname, "views"), { extension: "ejs" }));
// session
app.keys = ["koa-application"];
app.use(
    session(
        {
            maxAge: 1000 * 60 * 60,
            renew: true,
        },
        app
    )
);
// bodyparser
app.use(bodyparser());
// 注册路由
app.use(page.routes(), page.allowedMethods());
app.use(api.routes(), api.allowedMethods());

app.listen(3000);
